<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>

    <link rel="stylesheet" type="text/css" href="/static/Admin/plugins/colorpicker/colorpicker.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/custom-plugins/wizard/wizard.css" media="screen">

    <!-- Required Stylesheets -->
    <link rel="stylesheet" type="text/css" href="/static/Admin/bootstrap/css/bootstrap.min.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/fonts/ptsans/stylesheet.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/fonts/icomoon/style.css" media="screen">

    <link rel="stylesheet" type="text/css" href="/static/Admin/css/mws-style.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/icons/icol16.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/icons/icol32.css" media="screen">

    <!-- Demo Stylesheet -->
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/demo.css" media="screen">

    <!-- jQuery-UI Stylesheet -->
    <link rel="stylesheet" type="text/css" href="/static/Admin/jui/css/jquery.ui.all.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/jui/jquery-ui.custom.css" media="screen">

    <!-- Theme Stylesheet -->
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/mws-theme.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/themer.css" media="screen">

    <!-- 引入 layui -->
    <script src="/static/layui/layui.all.js"></script>
    <link rel="stylesheet" href="/static/layui/css/layui.css">

</head>

<body>

    <div class="mws-panel grid_8">
        <div class="mws-panel-header" style="height: 49px">
            <span>
                <i class="icon-table"></i> 首页推荐图列表</span>
        </div>
        <div class="mws-panel-body no-padding">
            <div id="DataTables_Table_1_wrapper" class="dataTables_wrapper" role="grid">
                <div id="DataTables_Table_1_length" class="dataTables_length">
                    <a href="/battery_banner/BannerAdd" class="btn btn-info">添加banner</a>
                </div>


                <table class="mws-datatable-fn mws-table dataTable" id="DataTables_Table_1" aria-describedby="DataTables_Table_1_info">
                    <thead>
                        <tr role="row">
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 275px;" aria-sort="ascending"
                                aria-label="Rendering engine: activate to sort column ascending">编号</th>
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 405px;" aria-label="Browser: activate to sort column ascending">标题</th>
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 368px;" aria-label="Platform(s): activate to sort column ascending">展示图</th>
                            <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 368px;" aria-label="Platform(s): activate to sort column ascending" data-type="{$order_type}" id="order_addtime">最后编辑时间</th>
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 368px;" aria-label="Platform(s): activate to sort column ascending"
                                id="add_time"  style="cursor:pointer;">描述</th>
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 368px;" aria-label="Platform(s): activate to sort column ascending"
                                id="delivery_time" >
                                <select name="is_show" id="js_isshow">
                                    <option value="">--全部--</option>
                                    <option value="1">当前显示</option>
                                    <option value="2">当前隐藏</option>
                                </select>
                            </th>
                            <th class="" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" style="width: 368px;" aria-label="Platform(s): activate to sort column ascending"
                                id="" style="cursor:pointer;">操作</th>
                        </tr>
                    </thead>

                    <tbody>
                        {foreach name="list" item="vo"}
                        {php}$vo = \app\admin\model\BatteryBanner::handleBannerInfo($vo){/php}

                        <tr class="gradeA odd">
                            <td class="">{$vo.banner_id}</td>
                            <td class="">{$vo.title}</td>
                            <td class="">
                                <img src="{$vo.banner_img}" alt="" width="120">
                            </td>
                            <td class="">{$vo.add_time|date="Y-m-d",###}</td>
                            <td class="">{$vo.describe}</td>
                            
                            <td>
                                {switch name="$vo.is_show"} {case value="1"}
                                <a href="javascript:;" class="btn btn-danger changeStatus" value="2" name="{$vo.banner_id}">点击下线</a>
                                {/case} {case value="2"} 
                                <a href="javascript:;" class="btn btn-success changeStatus" value="1" name="{$vo.banner_id}">点击上线</a>
                                {/case}  {/switch}
                            </td>
                            <td>
                                <a href="/battery_banner/BannerEdit/id/{$vo.banner_id}" class="btn btn-info" >修改</a>
                            </td>
                        </tr>
                        {/foreach}
                    </tbody>
                </table>
                <div class="dataTables_info" id="DataTables_Table_1_info">总数据条数 {$banner_amount}</div>
                <div class="" id="DataTables_Table_1_paginate" style="text-align: center">
                    {$page}
                </div>
            </div>
        </div>
    </div>




</body>
<!-- JavaScript Plugins -->
<script src="/static/Admin/js/libs/jquery-1.8.3.min.js"></script>
<script src="/static/Admin/js/libs/jquery.mousewheel.min.js"></script>
<script src="/static/Admin/js/libs/jquery.placeholder.min.js"></script>
<script src="/static/Admin/custom-plugins/fileinput.js"></script>

<!-- jQuery-UI Dependent Scripts -->
<script src="/static/Admin/jui/js/jquery-ui-1.9.2.min.js"></script>
<script src="/static/Admin/jui/jquery-ui.custom.min.js"></script>
<script src="/static/Admin/jui/js/jquery.ui.touch-punch.js"></script>

<!-- Plugin Scripts -->
<script src="/static/Admin/plugins/datatables/jquery.dataTables.min.js"></script>
<!--[if lt IE 9]>
        <script src="js/libs/excanvas.min.js"></script>
        <![endif]-->
<script src="/static/Admin/plugins/flot/jquery.flot.min.js"></script>
<script src="/static/Admin/plugins/flot/plugins/jquery.flot.tooltip.min.js"></script>
<script src="/static/Admin/plugins/flot/plugins/jquery.flot.pie.min.js"></script>
<script src="/static/Admin/plugins/flot/plugins/jquery.flot.stack.min.js"></script>
<script src="/static/Admin/plugins/flot/plugins/jquery.flot.resize.min.js"></script>
<script src="/static/Admin/plugins/colorpicker/colorpicker-min.js"></script>
<script src="/static/Admin/plugins/validate/jquery.validate-min.js"></script>
<script src="/static/Admin/custom-plugins/wizard/wizard.min.js"></script>

<!-- Core Script -->
<script src="/static/Admin/bootstrap/js/bootstrap.min.js"></script>
<script src="/static/Admin/js/core/mws.js"></script>

<!-- Themer Script (Remove if not needed) -->
<script src="/static/Admin/js/core/themer.js"></script>

<!-- Demo Scripts (remove if not needed) -->
<script src="/static/Admin/js/demo/demo.dashboard.js"></script>


<!-- select框 -->
<script>
    var args = {
        is_show: "{$is_show}",
    };

    var keyword = "{$keyword}";
    if (keyword.length > 0) {

        args.keyword = keyword;

    }
    function generateArgsStr() {
        var str = ""
        for (var name in args) {
            if (str.length == 0) {
                str = name + "/" + args[name];
            } else {
                str += "/" + name + "/" + args[name];
            }
        }
        return str;
    }
    var url = '__WebSite__/battery_banner/BannerList';

    $("#js_isshow option[value=" + args.is_show + "]").prop("selected", "selected");

    $("#js_isshow").on('change', function () {
        var val = $(this).val();
        args.is_show = val;
        url += "/" + generateArgsStr();

        console.log(url);

        location.href = url;
    })
</script>



<!-- 排序 -->
<script>
     $("#order_addtime").click(function () {
            var order_type = $(this).attr('data-type');

            order_type = order_type == 1? 2 : 1;

            keyword = "{$keyword}" != '' ? "{$keyword}" : '';
            is_show = "{$is_show}" == 'all' ? '' : "{$is_show}";

            var options = {
                url: "__WebSite__/battery_banner/BannerList",
                paramName: "order_type",
                newValue: order_type,
                keyword: keyword,
                is_show: is_show,
            };
            location.href = generateURL(options);
        });

</script>

<script type="text/javascript">
    var generateURL = function (options) {
        var url = options.url;
        var keyword = options.keyword;
        var is_show = options.is_show;


        if (is_show != '') {
            if ("/" != url[url.length - 1]) {
                url += "/";
            }
            url += 'is_show/' + is_show;
        }

        if (keyword != '') {
            if ("/" != url[url.length - 1]) {
                url += "/";
            }
            url += 'keyword/' + keyword;
        }
        if (-1 == url.indexOf(options.paramName)) {
            if ("/" != url[url.length - 1]) {
                url += "/";
            }
            url += options.paramName + "/" + options.newValue;
        } else {
            var re = new RegExp(options.paramName + "/\\d+");
            url = url.replace(re, options.paramName + "/" + options.newValue);
        }
        // url = url.replace(/[=?&]/g, "/");
        return url;
    };
</script>

<script>
    // ajax 状态修改
    $('.changeStatus').on('click', function () {
        var res = window.confirm('确定执行此项操作');
        if (res) {
            var id = $(this).attr('name');
            var status = $(this).attr('value');

            me = $(this);
            $.ajax({
                url: '/battery_banner/AjaxChangeStatus',
                type: 'post',
                data: { 'id': id, 'status': status },
                success: function (data) {

                    console.log(data);
                    if (data == 1) {
                        alert('显示成功');

                        if (status == 1) {

                            me.removeClass('btn-success').addClass('btn-danger').attr('value', 2).html('点击下线');

                        } else {

                            me.removeClass('btn-danger').addClass('btn-success').attr('value', 1).html('点击上线');
                        }
                    } else {
                        alert('操作失败');
                    }
                }
            })
        }
    })
</script>
</html>